package com.sc.justification;

import java.util.List;

import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreeModel;

import com.sc.justification.model.Menu;

public class MenuTreeModelBuilder {
	public static TreeModel getMenuTreeModel(List<Menu> menus){
	    DefaultMutableTreeNode      root = new DefaultMutableTreeNode("JTree");
		DefaultMutableTreeNode      parent;
		for (Menu menu : menus) {
			parent = new DefaultMutableTreeNode(menu.getName());
			root.add(parent);
			for(Menu child:menu.getChildren()){
			DefaultMutableTreeNode newChild = new DefaultMutableTreeNode(child.getName());
			newChild.setUserObject(child);
			parent.add(newChild);
			
			}
		}
	        return new DefaultTreeModel(root);
	}
}
